package org.eclipsecon.swtbot.example;

import static org.junit.Assert.assertEquals;

import org.eclipse.swtbot.eclipse.finder.SWTEclipseBot;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(SWTBotJunit4ClassRunner.class)
public class MyFirstTest02 {

	private static SWTEclipseBot	bot = new SWTEclipseBot();

//	@BeforeClass
//	public static void beforeClass() throws Exception {
//		new SWTEclipseBot().view("Welcome").close();
//	}

//	@Before
//	public void init() {
//		bot = new SWTEclipseBot();
//	}
	
//	@After
//	public void cleanup() {
//		bot = null;
//	}
	
	@Test
	public void title() {
//		String title = bot.getDisplay().getActiveShell().getText();
		SWTBot	bot = new SWTBot();;
		String title = bot.activeShell().getText();
		assertEquals("Java - Eclipse SDK", title);
	}

	@Test
	public void canCreateANewJavaProject() throws Exception {
		bot.menu("File").menu("New").menu("Project...").click();

		SWTBotShell shell = bot.shell("New Project");
		shell.activate();
		bot.tree().select("Java Project");
		bot.button("Next >").click();

		bot.textWithLabel("Project name:").setText("MyFirstProject");

		bot.button("Finish").click();
		// FIXME: assert that the project is actually created, for later
	}
	

	@AfterClass
	public static void sleep() {
		bot.sleep(2000);
	}

}
